﻿using System;
using System.ComponentModel;
using System.Configuration;
using Telerik.Web.UI;
using Thuoc24h.BasePage;
using Thuoc24h.Business;
using Thuoc24h.Common;

namespace Thuoc24h.AdminCP.Controls
{
    public partial class CategoryView : BaseUserControls
    {
        [Description("Category Type Id")]
        [Browsable(true)]
        [DefaultSettingValue("")]
        public int CategoryTypeId
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            hdfType.Value = CategoryTypeId.ToString();
            if (!Page.IsPostBack)
            {
             //  GetData();

            }
        }


        private void GetData()
        {
            gridData.DataSource = ReviewRepository.GetCategoryByType(CategoryTypeId); gridData.DataBind();
          
        }

        protected void gridData_ItemCommand(object sender, GridCommandEventArgs e)
        {
            string id = string.Empty;
        
            var commandName = e.CommandName;
           var gridDataItem = e.Item as GridDataItem;
            if (gridDataItem != null)
            {
                id = gridDataItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"].ToString();
            }
                 
                switch (commandName)
                {
                    case CommandNames.Edit:

                        if (CategoryTypeId == 1)
                        {
                            Utils.Redirect(UrlManager.Admin.CategoryProductEdit,id);
                        }
                        else
                        {
                            Utils.Redirect(UrlManager.Admin.CategoryNewsEdit,id);
                        }
                        break;
                    case CommandNames.Delete:
                        ReviewRepository.CategoryDelete(id.ToInt32Return0());
                        GetData();
                        break;
                    case "InitInsert":

                        if (CategoryTypeId == 1)
                        {
                            Utils.Redirect(UrlManager.Admin.CategoryProductEdit);
                        }
                        else
                        {
                            Utils.Redirect(UrlManager.Admin.CategoryNewsEdit);
                        }
                       
                        break;
                }



          




          
        }

        protected void gridData_PreRender(object sender, EventArgs e)
        {
        }
    }
}